package com.hnguigu.health.houduan.xsg.service_xsg.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hnguigu.health.houduan.xsg.service_xsg.t_userService;
import com.hnguigu.health.mapper.*;
import com.hnguigu.health.pojo.*;

import com.hnguigu.health.utils.jiangKangPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TuserServiceImpl implements t_userService {
    @Autowired(required = false)
    TUserMapper TUserMapper;
    @Resource
    TMenuMapper TMenuMapper;
    @Resource
    TMemberMapper tMemberMapper;
    @Resource
    TMemberDynamicinfoMapper tMemberDynamicinfoMapper;
    @Resource
    TMemberDynamicinfoMapper memberDynamicinfoMapper;
    @Resource
    BhMapper bhMapper;
    @Resource
    TMemberInfoMapper tMemberInfoMapper;
    @Resource
    THealthmgrMapper tHealthmgrMapper;
    @Resource
    ImgMapper imgMapper;
    @Resource
    TMemberExaminationMapper tMemberExaminationMapper;
    @Resource
    TOrderMapper tOrderMapper;
    @Resource
    LogtodayMapper logtodayMapper;
    @Resource
    TBodyTypeMapper tBodyTypeMapper;
    @Resource
    TQuestionEvaluationMapper tQuestionEvaluationMapper;
    @Resource
    TInterventionprogrammestableMapper tInterventionprogrammestableMapper;
    @Resource
    TFollowupjournalMapper tFollowupjournalMapper;
    @Resource
    TUserRoleMapper tUserRoleMapper;
    @Resource
    TRoleMapper tRoleMapper;


    @Override
    public TUser login(TUser user) {
        return TUserMapper.login(user);
    }


    @Override
    public Map<String, List<TMenu>> findMenuAll(String account) throws SQLException {
        Map<String,List<TMenu>> map=new HashMap<>();
        //根据用户名查询菜单
        List<TMenu> menuList=TMenuMapper.TmenuAllList(account);
        //现找到父菜单,再找子菜单
        for (TMenu m:menuList){
            //判断父级是id否为0
            if (m.getParentmenuid()==0){
                //再次遍历集合取对应子菜单
                List<TMenu> menus=new ArrayList<>();
                for (TMenu m1:menuList){
                    //如果父菜单id等于getParent_id()
                    if (m.getId()==m1.getParentmenuid()){
                        //把子菜单存入集合

                        menus.add(m1);
                    }
                }
                String gg=m.getName();
                map.put(gg,menus);//m是父菜单,menus是子菜单
            }
        }
        return map;
    }

    @Override
    public PageVo<TMember> TmemberAllList(Integer page, Integer num, TMember tMember) {
        PageHelper.startPage(page,num);
        List<TMember> allList = tMemberMapper.TmemberAllList(tMember);
        PageInfo<TMember> info =  new PageInfo<>(allList);
        PageVo pageVo = new PageVo();
        pageVo.setTotal(info.getTotal());
        pageVo.setRows(info.getList());
        return pageVo;

    }

    @Override
    public boolean TmemberAllDel(String[] ids) {
        return tMemberMapper.TmemberAllDel(ids);
    }

    @Override
    public int insertSelective(TMember record) {
        System.out.println(record);
        return tMemberMapper.insertSelective(record);
    }

    @Override
    public int insertSelective(TMemberDynamicinfo record) {
        return tMemberDynamicinfoMapper.insertSelective(record);
    }

    @Override
    public TMemberDynamicinfo TMemberExaminationByidAll(String id) {
        return memberDynamicinfoMapper.TMemberExaminationByidAll(id);
    }

    @Override
    public int updateByPrimaryKey(TMemberDynamicinfo record) {
        return memberDynamicinfoMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateByPrimaryKeySelective(TMember record) {
        return tMemberMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Bh selectByPrimaryKey(Integer id) {
        return bhMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Bh record) {
        return bhMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int insertSelective(TMemberInfo record) {
        return tMemberInfoMapper.insertSelective(record);
    }

    @Override
    public boolean TMemberExaminationAllDel(String[] ids) {
        return tMemberDynamicinfoMapper.TMemberExaminationAllDel(ids);
    }

    @Override
    public List<THealthmgr> t_healthmgrAllList() {
        return tHealthmgrMapper.t_healthmgrAllList();
    }



    @Override
    public PageVo<TMember> TmembersibiaoAllList(Integer page, Integer num) {
        PageHelper.startPage(page,num);
        List<TMember> allList = tMemberMapper.TmembersibiaoAllList();
        PageInfo<TMember> info =  new PageInfo<>(allList);
        PageVo pageVo = new PageVo();
        pageVo.setTotal(info.getTotal());
        pageVo.setRows(info.getList());
        return pageVo;
    }

    @Override
    public int insert(Img record) {
        return imgMapper.insert(record);
    }

    @Override
    public int updateStatus(TMemberExamination record) {
        return tMemberExaminationMapper.updateStatus(record);
    }

    @Override
    public List<Img> ImgALlLIst(String id) {
        return imgMapper.ImgALlLIst(id);
    }

    @Override
    public List<TMember> selectAllYuefen(String id) {
        return tMemberMapper.selectAllYuefen(id);
    }

    @Override
    public List<TOrder> selectToderfenlei(String id) {
        return tOrderMapper.selectToderfenlei(id);
    }

    @Override
    public List<TMemberExamination> shangchuanByAll(String id) {
        return tMemberExaminationMapper.shangchuanByAll(id);
    }

    @Override
    public int insert(Logtoday record) {
        return logtodayMapper.insert(record);
    }

    @Override
    public List<Logtoday> logtodayByAll(String id) {
        return logtodayMapper.logtodayByAll(id);
    }

    @Override
    public List<TOrder> yuyuecgAll(String id) {
        return tOrderMapper.yuyuecgAll(id);
    }

    @Override
    public List<TOrder> yuyuecgAll1() {
        return tOrderMapper.yuyuecgAll1();
    }

    @Override
    public List<TBodyType> TboDyTypeAll(String id) {
        return tBodyTypeMapper.TboDyTypeAll(id);
    }

    @Override
    public List<TBodyType> TboDyTypeAll1() {
        return tBodyTypeMapper.TboDyTypeAll1();
    }

    @Override
    public List<TMemberExamination> t_member_exam1(String id) {
        return tMemberExaminationMapper.t_member_exam1(id);
    }

    @Override
    public List<TMemberExamination> t_member_exam0(String id) {
        return tMemberExaminationMapper.t_member_exam0(id);
    }

    @Override
    public List<TMemberExamination> t_member_exam3() {
        return tMemberExaminationMapper.t_member_exam3();
    }

    @Override
    public List<TMemberExamination> t_member_exam4() {
        return tMemberExaminationMapper.t_member_exam4();
    }

    @Override
    public List<TQuestionEvaluation> TQusetionEvalluasiAllList() {
        return tQuestionEvaluationMapper.TQusetionEvalluasiAllList();
    }

    @Override
    public List<TInterventionprogrammestable> count() {
        return tInterventionprogrammestableMapper.count();
    }

    @Override
    public List<TMember> Tmecount() {
        return tMemberMapper.Tmecount();
    }

    @Override
    public List<TMember> TmecountData(String id) {
        return tMemberMapper.TmecountData(id);
    }

    @Override
    public List<TFollowupjournal> t_followCount() {
        return tFollowupjournalMapper.t_followCount();
    }

    @Override
    public PageVo<TUser> TuserAllList(Integer page, Integer num) {

        PageHelper.startPage(page,num);
        List<TUser> tUsers = TUserMapper.TuserAllList();
        PageInfo<TUser> info =  new PageInfo<>(tUsers);
        PageVo pageVo = new PageVo();
        pageVo.setTotal(info.getTotal());
        pageVo.setRows(info.getList());
        return pageVo;
    }

    @Override
    public int insertSelective(TUser record) {
        return TUserMapper.insertSelective(record);
    }

    @Override
    public int insertSelective(TUserRole record) {
        return tUserRoleMapper.insertSelective(record);
    }

    @Override
    public int insertSelective(THealthmgr record) {
        return tHealthmgrMapper.insertSelective(record);
    }

    @Override
    public THealthmgr Lastbean1() {
        return tHealthmgrMapper.Lastbean1();
    }

    @Override
    public TRole TRoleAllList(String name) {
        return tRoleMapper.TRoleAllList(name);
    }

    @Override
    public PageInfo<TMember> selectAllTmerber1(jiangKangPojo jiangkangpojo,int page,int num) {
           PageHelper.startPage(page,num);
        return new PageInfo<>(tMemberMapper.selectAllTmerber1(jiangkangpojo));
    }

    @Override
    public THealthmgr selectByName(String name) {
        return tHealthmgrMapper.selectByName(name);
    }

    @Override
    public PageInfo<TFollowupjournal> selectAllTFollow1(jiangKangPojo jiangkangpojo, int page, int num) {
        PageHelper.startPage(page,num);
        return new PageInfo<>(tFollowupjournalMapper.selectAllTFollow1(jiangkangpojo));
    }

    @Override
    public PageInfo<TFollowupjournal> selectAllTFollow2(jiangKangPojo jiangkangpojo, int page, int num) {
        PageHelper.startPage(page,num);
        return new PageInfo<>(tFollowupjournalMapper.selectAllTFollow2(jiangkangpojo));
    }

    @Override
    public List<TOrder> selectTorder(String[] id) {
        return tOrderMapper.selectTorder(id);
    }



}
